/* 
 *  Created By: Mike Stevens
 *  Project URL: http://www.codeplex.com/sitesecuritymgmt
 *  License: GNU GPL v2
 *  Copyright (C) 2008 Mike Stevens
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 */
using System;
using Microsoft.SharePoint;
using System.Collections.Generic;

namespace SiteSecurityManagement.Entities.SharePoint
{
    public class SPSiteObject
    {
        #region Members
        private static Guid m_siteCollectionId;
        private static Guid m_siteId;
        private static SPWeb m_site;

        private static string m_siteCollectionUrl;
        private static string m_siteUrl;
        #endregion

        #region Constructor/Destructor
        /// <summary>
        /// private constructor
        /// </summary>
        private SPSiteObject()
        { }
        #endregion

        #region Properties
        
        #endregion

        #region Methods
        /// <summary>
        /// Gets the site.
        /// </summary>
        /// <param name="siteCollectionID">The site collection ID.</param>
        /// <param name="siteID">The site ID.</param>
        /// <returns></returns>
        public static SPWeb GetSite(Guid siteCollectionID, Guid siteID)
        {
            m_site=null;
            m_siteCollectionId=siteCollectionID;
            m_siteId=siteID;

            SPSecurity.CodeToRunElevated code=new SPSecurity.CodeToRunElevated(GetSite);
            SPSecurity.RunWithElevatedPrivileges(code);

            return m_site;
        }

        /// <summary>
        /// Gets the site.
        /// </summary>
        /// <param name="siteCollectionUrl">The site collection URL.</param>
        /// <param name="siteUrl">The site URL.</param>
        /// <returns></returns>
        public static SPWeb GetSite(string siteCollectionUrl, string siteUrl)
        {
            m_site = null;
            m_siteCollectionUrl = siteCollectionUrl;
            m_siteUrl = siteUrl;

            SPSecurity.CodeToRunElevated code = new SPSecurity.CodeToRunElevated(GetSiteByUrl);
            SPSecurity.RunWithElevatedPrivileges(code);

            return m_site;
        }

        /// <summary>
        /// Gets the site by URL.
        /// </summary>
        private static void GetSiteByUrl()
        {
            SPSite siteCollection = new SPSite(m_siteCollectionUrl);
            m_site = siteCollection.AllWebs[m_siteUrl];
        }

        /// <summary>
        /// Gets the site.
        /// </summary>
        private static void GetSite()
        {
            SPSite siteCollection = new SPSite(m_siteCollectionId);
            m_site = siteCollection.AllWebs[m_siteId];
        }
#endregion

    }
}
